How is main() function not mangled in C++
=================================================

When building a parser tree, GCC generates a "main" identifier node::

  // in gcc/tree.h
  #define main_identifier_node             global_trees[TI_MAIN_IDENTIFIER]
  #define MAIN_NAME_P(NODE) \
    (IDENTIFIER_NODE_CHECK (NODE) == main_identifier_node)
  // in gcc/c-family/c-common.c
  main_identifier_node = get_identifier ("main");

GCC checks main and set it as a C declaration in gcc/cp/decl.c::

  /* `main' and builtins have implicit 'C' linkage.  */
  if (ctype == NULL_TREE
      && DECL_FILE_SCOPE_P (decl)
      && current_lang_name == lang_name_cplusplus
      && (MAIN_NAME_P (declarator)
      || (IDENTIFIER_LENGTH (declarator) > 10
          && IDENTIFIER_POINTER (declarator)[0] == '_'
          && IDENTIFIER_POINTER (declarator)[1] == '_'
          && strncmp (IDENTIFIER_POINTER (declarator)+2,
              "builtin_", 8) == 0)
      || (targetcm.cxx_implicit_extern_c
          && (targetcm.cxx_implicit_extern_c
          (IDENTIFIER_POINTER (declarator))))))
    SET_DECL_LANGUAGE (decl, lang_c);

Also, the compiler don't warn when main() doesn't have a return statement. This is also checked using MAIN_NAME_P macro.
